<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	
	String type = (String)request.getAttribute("type");
	String brandId = (String)request.getAttribute("brandId");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>新增商品品牌</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/head.jsp"></jsp:include>
	<script type="text/javascript">
		var type = "<%=type%>";
		var brandId = "<%=brandId%>";
		
		function save(){
			if($('#fm').form('validate')){
				var url =  path;
			
				if(type == "add") {
					url += "/brand/save.do?t="+new Date().getTime();
				}else {
					url += "/brand/update.do?t="+new Date().getTime();
					url += "&brandId="+brandId;
				}
				
				var data = "&name="+escape(escape($('#name').val()));
				data += "&description="+escape(escape($('#description').val()));
				data += "&imageUrl="+escape(escape($('#imageUrl').val()));
				
				$.ajax({
				  url: url,
				  data:data,
				  success: function(data) {
					   if(data == "1"){
						   window.location = path+"/brand/brandMgr.do";
					   }else{
						   alertBox("操作失败！");
					   }
				  }
				});
				
			}
		}
		
		function callback(){
			window.location = path+"/brand/brandMgr.do";
		}
		
		function selectImage(){
	       	var w =(screen.width-300)/2;
			var h = (screen.height-60)/2;
			var ret = window.showModalDialog(path+"/page/common/image-upload.jsp",window,"dialogWidth:300px;dialogHeight:60px;dialogTop:"+h+"px;dialogLeft:"+w+"px;help:no;status:no;center:yes");
			if(ret != null){
				$('#image').attr('src',path+"/"+ret[0][0]);
				$('#imageUrl').attr('value',ret[0][0]);
			}
		}
	</script>
  </head>
  
  <body>
   <div class="right">
	<h1><b>${type=='add'?'新增商品品牌':'编辑商品品牌' }</b><span><img src="<%=basePath%>images/right_h1bg2.jpg" width="3" height="29" /></span></h1>
	<form id="fm">
	<div class="ri_main">
		<table width="97%" border="0" cellspacing="1" cellpadding="8" style="background:#d9d9d9;">
		  <tr>
		    <td width="21%" align="right" bgcolor="#FFFFFF">名称：</td>
		    <td width="79%" bgcolor="#FFFFFF">
		      <input id="name" name="name" class="easyui-validatebox" required="true" style="width:200px;" value="${brand != null?brand.name:''}">
		    </td>
		  </tr>
		  <tr>
		    <td align="right" bgcolor="#FFFFFF">图片：</td>
		    <td bgcolor="#FFFFFF">
		    	<img id="image" width="200" height="200" name="image" src="<%=basePath %>${brand != null?brand.imageUrl:''}"></img>
		    	<input type="hidden" id="imageUrl" name="imageUrl" value="${brand != null?brand.imageUrl:''}">
		    	<input type="button" onclick="selectImage()" value="选择" />
		    </td>
		   </tr>
		   
		    <tr>
		    <td align="right" bgcolor="#FFFFFF">描述：</td>
		    <td bgcolor="#FFFFFF">
		    	<input id="description" name="description" class="easyui-validatebox" required="true" style="width:200px;" value="${brand != null?brand.description:''}">
		    </td>
		   </tr>
		   
		   <tr>
		    <td align="center" bgcolor="#FFFFFF" colspan="2">
				<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">保存</a>
				<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-undo" onclick="callback()">取消</a>
			</td>
		   </tr>
		</table>
	</div>
	</form>
	</div>
  </body>
</html>
